import { modal } from 'vue-strap'
import { showMsg, importInviteUserList } from '../../../../vuex/action'

export default {
  name: 'code-excel',
  data() {
    return {
      title: '导入交易数据',
      type: '1',
    }
  },
  props: ['showImport'],
  components: {
    'vue-modal': modal
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xImportInviteUserList: importInviteUserList
    }
  },
  methods: {
    showImportExcel() {
      this.showImport = true
    },
    submit() {
      var file = this.$els.settlefile.files[0]
      if (file) {
        var formData = new FormData()
        formData.append('excelFile', file)
        formData.append('type', this.type)
        this.xImportInviteUserList(formData)
        .then((data) => {
          this.showImport = false
        })
          .catch((res) => {
            this.xShowMsg({
              type: 'danger',
              content: res.error_msg
            })
          })
      } else {
        this.xShowMsg({
          type: 'danger',
          content: '请选择导入文件'
        })
      }
    }
  }
}
